package org.terrier.matching.models.basicmodel;

import org.terrier.matching.models.Idf;

import org.terrier.utility.ApplicationSetup;

public class PSpdf extends BasicModel {
	/*
     * exp pdf 
     */
    double lambda = Double.parseDouble(ApplicationSetup.getProperty(
    		"distribution.parameter.0", "0.8"));//0.71

	@Override
	public String getInfo() {
		return "PSpdf";
	}

	@Override
	public double score(double tf, double documentFrequency,
			double termFrequency, double keyFrequency, double documentLength) {
		
		return keyFrequency * (tf * Idf.log(1.0D / lambda)
				+ lambda * Idf.REC_LOG_2_OF_E
				+ 0.5d * Idf.log(2 * Math.PI * tf)
				+ tf * (Idf.log(tf) - Idf.REC_LOG_2_OF_E));
		
	}
	
	public void initModel(){
		String value = null;
		if ((value = ApplicationSetup.getProperty("distribution.parameter.0", "0.8d"))!=null){
			this.lambda = Double.parseDouble(value);
		}
	}

}
